#include <iostream>
using std::cout;
using std::endl;

class Point
{
public:
    Point(int x,int y = 0)
    : _ix(x)
    , _iy(y)
    {
        cout << "Point(int,int)" << endl;
    }

    ~Point(){
        cout << "~Point()" << endl;
    }

    
    //如果拷贝构造函数的形式是Point(const Point rhs)
    //Point pt2(pt)
    //形参的初始化const Point rhs = pt;
    //触发拷贝构造的第二种调用时机
    //会再次对pt进行复制
    //const Point rhs = pt
    //...
    //这样下去会导致拷贝构造无限调用，直至栈溢出，程序崩溃
    Point(const Point & rhs)
    : _ix(rhs._ix)
    , _iy(rhs._iy)
    {
        cout << "Point(const Point&)" << endl;
    }

    //如果拷贝构造的形参是非const引用
    //(1)无法避免在函数体中修改原对象的内容
    //(2)无法使用右值属性的对象复制出新的对象
    /* Point(Point & rhs) */
    /* : _ix(rhs._ix) */
    /* , _iy(rhs._iy) */
    /* { */
    /*     /1* rhs._ix = 10000; *1/ */
    /*     cout << "Point(const Point&)" << endl; */
    /* } */

    void print(){
        cout << "(" << _ix
            << "," << _iy
            << ")" << endl;
    }
private:
    int _ix = 10;
    int _iy = 10;
};



void test0(){
    Point pt(10,8);
    Point pt2(pt);
    pt2.print();
    pt.print();

    Point pt3 = Point(7,8);

    

}

int main(void){
    test0();
    return 0;
}
